package com.learn.xueer.app.network

import com.learn.xueer.data.model.bean.*
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.http.*

/**
 * 作者　: hegaojian
 * 时间　: 2019/12/23
 * 描述　: 网络API
 */
interface ApiService {

    companion object {
        const val SERVER_URL = "https://d-xueer.bigchun.com/"
    }

    /**
     * 登录
     */
    @FormUrlEncoded
    @POST("api/user/login")
    suspend fun login(
        @Field("captcha") captcha: String,
        @Field("captcha_token") captcha_token: String,
        @Field("account") account: String,
        @Field("password") password: String,
        @Field("school_id") school_id: String,
        @Field("type") type: String
    ): ApiResponse<LoginResponse?>

    @FormUrlEncoded
    @POST("api/sms/send")
    suspend fun sendSms(
        @Field("mobile") mobile: String,
        @Field("event") event: String
    ): ApiResponse<LoginResponse?>

    /**
     * 学校列表
     */
    @FormUrlEncoded
    @POST("api/user/getSchoolList")
    suspend fun getSchoolList(
        @Field("city") city: String,
        @Field("name") name: String
    ): ApiResponse<ArrayList<SchoolResponse>?>

    @FormUrlEncoded
    @POST("api/user/retrievepwd")
    suspend fun resetPass(
        @Field("captcha") captcha: String,
        @Field("captcha_token") captcha_token: String,
        @Field("mobile") mobile: String,
        @Field("mobile_captcha") mobile_captcha: String,
        @Field("newpassword") newpassword: String
    ): ApiResponse<Any?>

    @FormUrlEncoded
    @POST("api/user/changemobile")
    suspend fun changeMobile(
        @Field("captcha") captcha: String,
        @Field("captcha_token") captcha_token: String,
        @Field("mobile") mobile: String,
        @Field("mobile_captcha") mobile_captcha: String
    ): ApiResponse<Any?>

    /**
     * 反馈
     */
    @FormUrlEncoded
    @POST("api/index/addFeedback")
    suspend fun feedBack(
        @Field("content") content: String
    ): ApiResponse<ArrayList<Any>?>

    /**
     * 个人信息
     */
    @POST("api/user/getuserinfo")
    suspend fun getUserInfo(): ApiResponse<UserInfoResponse?>

    /**
     * 个人信息
     */
    @GET("api/message/getList")
    suspend fun messageList(): ApiResponse<MessageResponse?>

    /**
     * 设置信息
     */
    @POST("api/index/getSetting")
    suspend fun getSetting(): ApiResponse<SettingResponse?>

    @POST("api/index/getAbout")
    suspend fun getAbout(): ApiResponse<AboutResponse?>

    @POST("api/answer/getStudyLogList")
    fun studyHistory(@Header("token") token: String): Call<ResponseBody>

    @GET("api/answer/getMissionHistory")
    suspend fun missionHistory(@Query("month") month: String): ApiResponse<MissionHistoryResponse?>

    /**
     * 我的订单
     */
    @GET("api/vip/getOrderList")
    suspend fun getOrderList(): ApiResponse<Any?>

    /**
     * 书籍会员列表
     */
    @GET("api/vip/getVip")
    suspend fun getVip(): ApiResponse<VipResponse?>

    /**
     * 会员详情
     */
    @GET("api/vip/getVipInfo")
    suspend fun getVipInfo(@Query("id") id: String): ApiResponse<VipDetailResponse?>

    /**
     * 护眼
     */
    @FormUrlEncoded
    @POST("api/user/updateEye")
    suspend fun updateEye(@Field("is_eyeshield") isEyeshield: String): ApiResponse<Any?>

    @FormUrlEncoded
    @POST("api/user/profile")
    suspend fun updateProfile(@Field("avatar") avatar: String): ApiResponse<Any?>

    /**
     * 常见问题
     */
    @POST("api/index/getProblem")
    suspend fun problem(): ApiResponse<ArrayList<QuestionResponse>?>

    @POST("api/address/area")
    suspend fun area(): ApiResponse<AreaResponse?>

    /**
     * 验证码
     */
    @GET("api/common/captcha")
    fun captcha(
        @Query("id") id: String
    ): Call<ResponseBody>

    /**
     * 首页
     */
    @GET("api/index/getIndexSetting")
    suspend fun getHomeConfig(): ApiResponse<HomeInfoResponse>

    /**
     * 听说-教材列表
     */
    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/hearsay")
    suspend fun getHearSay(@Body body: RequestBody): ApiResponse<MutableList<HearSayResponse>?>


    @POST("api/vip/createOrder")
    suspend fun createOrder(): ApiResponse<Any?>

    /**
     * 听说-教材详情
     */
    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/hearsay/detail")
    suspend fun bookInfo(@Body body: RequestBody): ApiResponse<HearSayResponse?>

    /**
     * 听说-教材章节列表
     */
    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/hearsay/chapterlist")
    @FormUrlEncoded
    suspend fun bookSection(
        @Field("id") id: String,
        @Field("order") order: String
    ): ApiResponse<MutableList<BookSectionResponse>?>

    /**
     * 听说-教材章节详情
     */
    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/hearsay/chapterdetail")
    @FormUrlEncoded
    suspend fun sectionDetail(
        @Field("id") id: String,
        @Field("pid") pid: String
    ): ApiResponse<SectionDetailResponse>

    /**
     * 听说-模拟测试题
     */
    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/hearsay/questions")
    @FormUrlEncoded
    suspend fun hearsayQuestions(@Field("id") id: String): ApiResponse<HearSayQuestionResponse>

    /**
     * 教材
     */
    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/textbook")
    suspend fun textBook(): ApiResponse<MutableList<TextBookResponse>>

    /**
     * 教材单元
     */
    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/textbook/unit")
    @FormUrlEncoded
    suspend fun textBookUnit(@Field("id") id: String): ApiResponse<MutableList<TextBookUnitResponse>>

    /**
     *  单元单词列表
     */
    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/textbook/unitword")
    @FormUrlEncoded
    suspend fun unitWord(@Field("id") id: String): ApiResponse<MutableList<UnitWordResponse>>

    /**
     *  单词详情
     */
    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/textbook/wordinfo")
    @FormUrlEncoded
    suspend fun wordInfo(@Field("id") id: String): ApiResponse<MutableList<WordInfoResponse>>

    @Multipart
    @POST("api/common/upload")
    fun uploadFile(
        @Part file: MultipartBody.Part,
        @Header("token") token: String
    ): Call<ResponseBody>

    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/reciting/pkIndex")
    suspend fun pkRecord(): ApiResponse<PkRecordResponse>

    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/reciting/pk")
    suspend fun getPkInfo(): ApiResponse<PkResponse>

    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/answer/wordPkAnswer")
    suspend fun submitAnswer(
        @Field("id") id: String,
        @Field("wid") wid: String,
        @Field("pk_id") pkId: String
    ): ApiResponse<PkResponse>

    @Headers("token:72a6efa9-28e4-43f4-a70f-bd6a0b385789")
    @POST("api/reciting/savePk")
    @FormUrlEncoded
    suspend fun savePk( @Field("type") id: Int): ApiResponse<PkResultResponse>
}